#include <sys/types.h>
#include <unistd.h>
#include <iostream>
#include <sstream>

using namespace std;

// this program demonstrates usage of C++ iostreams to use typesafe
// formatting. C's printf() family of funtions is inherently unsafe,
// and only suitable for programmers who tend to know what they're
// doing.

int main()
{
    pid_t pid = getpid();

    // the C++ compile will deduce the type of the pid parameter, and
    // do the right thing.
    cout << "Dieses Programm hat PID " << pid << endl;

    // ostringstream is a class that allocates memory to hold the
    // formatted incarnation of what you shove in.
    ostringstream msg_buffer;
    msg_buffer << "Dieses Programm hat PID " << pid;
    // retrieve the buffer that was allocated.
    cout << msg_buffer.str() << endl;

    return 0;
}
